package br.com.tcc.systemdx.persistence.hibernate;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.orm.hibernate3.SessionFactoryUtils;
import org.springframework.transaction.annotation.Transactional;

import br.com.tcc.systemdx.commons.persistence.hibernate.GenericHibernateDAOImpl;

@Transactional
public abstract class AbstractHibernateDAOImpl<T, ID extends Serializable> extends
		GenericHibernateDAOImpl<T, ID> implements ApplicationContextAware, Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1017109116455867914L;
	
	private transient ApplicationContext applicationContext;
	
	@Override
	@Autowired
	public void setSessionFactory(SessionFactory s) {
		super.setSessionFactory(s);
	}
	
	@Override
	protected Session _getSession() {
		return SessionFactoryUtils.getSession(this.getSessionFactory(), true);
	}
	
	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		this.applicationContext = arg0;
	}
	
	/**
	 * @return the applicationContext
	 */
	protected ApplicationContext getApplicationContext() {
		return applicationContext;
	}
	
	

}
